home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8319 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.6 KB  |  95 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: gnu.gcc.help,comp.lang.c
  4. Subject: Re: Is this a compiler bug?
  5. Date: 01 Mar 1996 01:31:40 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb29183140@qcd.lanl.gov>
  8. References: <3135FEDB.65AA@carbon.chem.nyu.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: "Edward J. Huff"'s message of Thu, 29 Feb 1996 14:30:35 -0500
  13.  
  14. In article <3135FEDB.65AA@carbon.chem.nyu.edu>
  15. "Edward J. Huff" <huffe@carbon.chem.nyu.edu> writes:
  16.  
  17. JH: The gcc documentation states:
  18. JH: > If the compiler does not produce an error message for invalid 
  19. JH: > input, that is a compiler bug. However, you should note that 
  20. JH: > your idea of "invalid input" might be my idea of "an extension"
  21. JH: > or "support for traditional practice".
  22. JH: 
  23. JH: Is this a bug?  Or is it "support for traditional practice"?
  24.  
  25. I do not know, but the code you have presented it invokes undefined
  26. behaviour. So, the compiler has no responsibility to produce a
  27. diagnostic for it. Actually, with my standard conformance flags, gcc
  28. does produce a diagnostic.
  29.  
  30. As this is crossposted to gnu.gcc.help, your question probably has a
  31. wider scope of what _should_ be the behaviour of the compiler. I'll
  32. let others decide that, but in comp.lang.c, I will just say, don't
  33. code this way.
  34.  
  35. JH: 
  36. JH: carbon% head static*.c
  37. JH: ==> static_bug.c <==
  38. JH: static const char foo[];
  39.  
  40. A static variable without an initializer and in the file scope cannot
  41. have an incomplete type. For some reason which I cannot fathom (ask in
  42. comp.std.c to see if anyone there knows), the standard does not
  43. _require_ a diagnostic from a compiler if this construct is used:
  44. rather it then allows the compiler complete freedom to do whatsoever
  45. it chooses with the entire program.
  46.  
  47. As you posted in comp.lang.c, and your code is less-than-perfect
  48. portable C, let me point out the following
  49.  
  50. JH: int
  51. JH: main(int argc, const char *argv[]) {
  52.  
  53. The use of const in this context again invokes undefined
  54. behaviour. According to the standard, the return type of main must be
  55. int, and it can have either 0 or two parameters: and if it has two
  56. parameters, they shall be of type int and char*[] respectively. 
  57.  
  58. JH:   printf("foo = '%s'\n",foo);
  59.  
  60. This invokes undefined behaviour. A varargs function like printf
  61. cannot be called without a prototype in scope. You provided
  62. none. #include <stdio.h> if you want to use printf.
  63.  
  64. JH:   return 0;
  65. JH: }
  66. JH: 
  67. JH: #ifdef DEFINE_IT
  68. JH: static const char foo[] = "bar";
  69.  
  70. This is valid because the declaration has an initializer, so the above
  71. discussion does not apply. The declaration in this case actually
  72. completes the type.
  73.  
  74. JH: #endif
  75. JH: 
  76. JH: ==> static_bug2.c <==
  77. JH: const char foo[] = "baz";
  78.  
  79. This declaration is also valid for reasons similar to that stated
  80. above. In this case, _even without the initializer_, the declaration
  81. would have been valid, because it does not specify the keyword
  82. static. As the type is not completed by the end of the translation
  83. unit, it would then behave like the declaration `const char foo[1] =
  84. {0};' (according to TC1 to the standard).
  85.  
  86. Cheers
  87. Tanmoy
  88. --
  89. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  90. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  91. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  92. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  93. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  94. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  95.